<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="referrer" content="no-referrer" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <!-- 导入样式表 -->
    <link rel="stylesheet" href="./assets/news.css" />
  </head>

  <body>
    <!-- 新闻列表 -->
    <div id="news-list">
      <!-- 新闻的 item 项 -->
    
    </div>
 
    <script src="./node_modules/axios/dist/axios.min.js"></script>
<script>
    

    async function show(){
 
      const res=   await axios({

        url:'http://192.168.36.234:9000/api/news'
       })
       console.log(res);
    document.querySelector('#news-list').innerHTML= res.data.map( item=>{
 return     ` 
      <!-- 新闻的 item 项 -->
      <div class="news-item">
        <img class="thumb" src="${item.pic_url}" alt="" />
        <div class="right-box">
          <!-- 新闻标题 -->
          <h1 class="title">${item.title}</h1>
          <div class="footer">
            <div>
              <img src="${item.avatar}" alt="" />
              <!-- 新闻来源 -->
              <span>${item.nickname}</span>&nbsp;&nbsp;

              <!-- 发布日期 -->
              <span>${item.publish_time}</span>
            </div>
            <!-- 评论数量 -->
            <span>评论数：${item.comment_count}</span>
          </div>
        </div>
      </div>
 ` 
       }).join('')
    }

    show()

</script>

  </body>
</html>
